﻿$(document).ready(function(){
	/*全选/取消全选*/
	$("#chk_all").click(function(){
		$("input[name='chk_list']").prop("checked", this.checked);
	});
	$("input[name='chk_list']").click(function() {
		var $subs = $("input[name='chk_list']");
		$("#chk_all").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false);
	});
});

function display(id,e){
	$(".listmenu:not(#divhidden"+id+")").fadeOut(200);
	if(e.pageY>450){
		$("#divhidden"+id).css("margin-top","-110px");
	}
	$("#divhidden"+id).slideToggle(200);
}
function onhidden(id){
	$("#divhidden"+id).fadeOut(200);
} 
//获取被选中的checkbox的值
function getCheckedValue(){
	var chk_list = document.getElementsByName('chk_list');
	var chkString = "";
	for(var i=0;i<chk_list.length;i++){
		if(chk_list[i].checked){
			 chkString =chk_list[i].value+","+chkString;
		}
	}
	return chkString.substring(0,chkString.length-1);
}

//更改状态
function _changeStatus(obj,_url){
	art.dialog.confirm('确认修改状态?', function(){
		var id = obj.id;
		var status = obj.name;
		var name;
		var css = "";
		if(status==1){
			css="statusEnabled";
			name = "0";
		}else{
			css = "statusDisabled";
			name = "1";
		}
		$.ajax({  
		    type: "post",  
		    async: false,
		    url: _url,
		    data: "id=" + id +"&status="+status,  
		    success: function(data){ 
		    	if(data=='true'){
				    art.dialog.tips('操作成功');
				    $("#"+id).attr("class",css);
				    $("#"+id).attr("name",name);
		    	}else{
		    		art.dialog.tips('操作失败');
		    	}
		    }
		});
	}, function(){
	    art.dialog.tips('取消操作');
	});
}

//单个删除
function _deleteListOne(_url) {
	art.dialog.confirm('确认删除所选项', function(){
		$.ajax({  
		    type: "post",  
		    async: false,
		    url: _url,
		    success: function(data){ 
		    	if(data=='true'){
				    art.dialog.tips('操作成功');
				    setTimeout("_refreshList()",1000);
		    	}else{
		    		art.dialog.tips('操作失败');
		    	}
		    }
		});
	}, function(){
	    art.dialog.tips('取消操作');
	});
}

//批量删除
function _deleteListBatch(_url){
	var ids = getCheckedValue();
	if(ids==""||ids==null){
		art.dialog.tips('请至少选择一项');
	}else{
		art.dialog.confirm('确认删除所选项', function(){
			$.ajax({  
			    type: "post",  
			    async: false,
			    url: _url,
			    data: "ids=" + ids,
			    success: function(data){ 
			    	if(data=='true'){
					    art.dialog.tips('操作成功');
					    setTimeout("_refreshList()",1000);
			    	}else{
			    		art.dialog.tips('操作失败');
			    	}
			    }
			});
		}, function(){
		    art.dialog.tips('取消操作');
		});
	}
}
//打开详情
function _detail(_url,title) {
	__openWindow(_url,title);
}
//打开新增
function _add(_url,title) {
	__openWindow(_url,title);
}
//打开修改
function _modify(_url,title) {
	__openWindow(_url,title);
}
//刷新页面
function _refreshList(){
	document.srcForm.submit();
}
//条件查询
function _search(){
	var currentPage = $("#currentPage");
	if(currentPage!=null && typeof(currentPage) != "undefined"){
		currentPage.val(1);
	}
	document.srcForm.submit();
}
